package cn.xiaoqintools.studypark.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;


import butterknife.Bind;
import cn.xiaoqintools.studypark.R;

/**
 * Created by zzd on 2015/10/24.
 */
public class BaseTabActivity extends BaseActivity {


    protected int getLayoutId() {
        return R.layout.activity_base_tab;
    }

    protected void initFragment(Fragment to) {
        FragmentTransaction mFragmentTransaction;
        mFragmentTransaction = getSupportFragmentManager().beginTransaction();
        mFragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
        if (!to.isAdded()) {
            mFragmentTransaction.add(R.id.realtabcontent, to).commit();
        }
    }

    protected void switchFragment(Fragment from, Fragment to) {
        FragmentTransaction mFragmentTransaction;
        mFragmentTransaction = getSupportFragmentManager().beginTransaction();
        mFragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
        if(from!=null) {
            if (!to.isAdded()) {
                mFragmentTransaction.hide(from).add(R.id.realtabcontent, to).commit();
            } else {
                mFragmentTransaction.hide(from).show(to).commit();
            }
        }else{
            initFragment(to);
        }
    }

}
